﻿using DogModel.Common;
using HelperCommon.Authorizations.IssJWT;
using IDogService;
using Microsoft.AspNetCore.Mvc;

namespace DogAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        protected readonly IUserInfoService userInfoService;

        public LoginController(IUserInfoService _userInfoService)
        {
            userInfoService = _userInfoService;
        }

        [HttpGet]
        public MessageModel GetJwtToken(string name, string pwd)
        {
            var user = userInfoService.GetByName(new DogModel.UserInfo { Name = name, PassWord = pwd });
            if (user != null)
            {
                var jwt = JwtHelper.IssueJwt(user.Id.ToString(), user.Name);
                return new MessageModel { Message = jwt, Status = 200, Success = true };
            }
            return new MessageModel { Message = "未成功", Status = 200, Success = false };
        }
    }
}